require(grDevices)
require(showtext)

args <- commandArgs(TRUE)

library(RColorBrewer)
library(showtext)
showtext_auto(enable=TRUE)

png("latency-compare.png", width=1200, height=800)


data1 <- read.csv(args[1], header=FALSE, sep=' ', colClasses=c("numeric", "numeric"))
x1 <- data1[,1]
y1 <- data1[,2]

data2 <- read.csv(args[2], header=FALSE, sep=' ', colClasses=c("numeric", "numeric"))
x2 <- data2[,1]
y2 <- data2[,2]

plot.new()
plot.window(xlim=c(1,250), log="y", ylim=c(1, max(y1,y2)), xaxs="i", yaxs="i")
title(xlab="latency in microseconds", ylab="occurences + 1")
legend("top", c("preempt-rt", "non-rt"), col=c("green", "red"), bty="n", lwd=2, cex=1.5, seg.len=c(8))
grid(50, NULL)
lines(x1, y1, type="l", lwd=1, col="red")
lines(x2, y2, type="l", lwd=1, col="green")
axis(1, at=seq(0, 250, by=5), cex.axis=1)
axis(2, at=c(0, 1, 10, 10^2, 10^3, 10^4, 10^5, 10^6), cex.axis=1)
box()

dev.off()
